package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.entity.MqUploadResult;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class DeviceUploadTimeReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        // *TJ,7893267561,V4,UPLOAD,130305,050316,5,A,2212.8745,N,11346.6574,E,14.28,028,460,2,1988,23567,00,00,00,20902,FFFFFFFF#
        // new ：*WT,800115470000876,V4,UPLOAD,135303,m2,280,134757,V,0.0000,S,0.0000,W,0.00,0,050721,FDFFFFFF
        String[] split = data.split(",");
        String imei = split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber = split[4];
        String mode = split[5];//工作模式
        String interval = split[6];//上报时间间隔
        String deviceTime = split[7];//指令返回信息的时间
        String lat = split[9];
        String lng = split[11];
        String speed = split[13];
        String orientation = split[14];
        //基站信息
  /*      String mcc=split[14];//移动设备国家代码
        String singal=split[18];//信号值
        Integer gpsNum=Integer.parseInt(split[19]);//gps卫星数
        String battery=split[20];//电量*/
        String deviceDate = split[15];
        String deviceStatus = split[16];
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqUploadResult mqUploadResult = new MqUploadResult();
        mqUploadResult.setCommandNumber(commandNumber);
        mqUploadResult.setImei(imei);
        mqUploadResult.setDeviceDate(deviceDate);
        mqUploadResult.setDeviceTime(deviceTime);
        mqUploadResult.setInterval(Integer.parseInt(interval));
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqUploadResult.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().uploadResponse(mqUploadResult);
        return imei;
    }
}
